package com.ttt.adbgui.guiimp;

import com.ttt.adbgui.function.AdbMonkey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseListener;
import java.util.ArrayList;

@Component
@Slf4j
public class MonkeyImp {

    @Autowired
    private AdbMonkey adbMonkey;

    public void starImp(ArrayList<JComponent> jComponents){

        // 包名
        JTextPane packageName = (JTextPane) jComponents.get(0);
        packageName.setText("包名：");
        packageName.setBounds(10,10,70,20);
        packageName.setBorder(null);
        packageName.setForeground(Color.BLACK);
        packageName.setEditable(false);
        // 日志级别
        JTextPane logLevel = (JTextPane) jComponents.get(1);
        logLevel.setText("日志级别(-V)：");
        logLevel.setBounds(270,10,90,20);
        logLevel.setBorder(null);
        packageName.setForeground(Color.BLACK);
        logLevel.setEditable(false);
        // 步骤延迟
        JTextPane stepDelay = (JTextPane) jComponents.get(2);
        stepDelay.setText("步骤延迟(ms)：");
        stepDelay.setBounds(540,10,90,20);
        stepDelay.setBorder(null);
        packageName.setForeground(Color.BLACK);
        stepDelay.setEditable(false);
        // seed
        JTextPane seedValue = (JTextPane) jComponents.get(3);
        seedValue.setText("seed：");
        seedValue.setBounds(10,60,70,20);
        seedValue.setBorder(null);
        packageName.setForeground(Color.BLACK);
        seedValue.setEditable(false);
        // 事件数量
        JTextPane functionNum = (JTextPane) jComponents.get(4);
        functionNum.setText("事件数量：");
        functionNum.setBounds(270,60,90,20);
        functionNum.setBorder(null);
        packageName.setForeground(Color.BLACK);
        functionNum.setEditable(false);
        // 日志位置
        JTextPane logPath = (JTextPane) jComponents.get(5);
        logPath.setText("日志位置：");
        logPath.setBounds(540,60,90,20);
        logPath.setBorder(null);
        packageName.setForeground(Color.BLACK);
        logPath.setEditable(false);
        // 编辑输入框1
        JTextField packageNameField = (JTextField) jComponents.get(6);
        packageNameField.setColumns(100);
        packageNameField.setBounds(90,10,140,20);
        // 编辑输入框2
        JTextField logLevelField = (JTextField) jComponents.get(7);
        logLevelField.setColumns(100);
        logLevelField.setBounds(360,10,140,20);
        // 编辑输入框3
        JTextField stepDelayField = (JTextField) jComponents.get(8);
        stepDelayField.setColumns(100);
        stepDelayField.setBounds(630,10,140,20);
        // 编辑输入框4
        JTextField seedValueField = (JTextField) jComponents.get(9);
        seedValueField.setColumns(100);
        seedValueField.setBounds(90,60,140,20);
        // 编辑输入框5
        JTextField functionNumField = (JTextField) jComponents.get(10);
        functionNumField.setColumns(100);
        functionNumField.setBounds(360,60,140,20);
        // 编辑输入框6
        JTextField logPathField = (JTextField) jComponents.get(11);
        logPathField.setColumns(100);
        logPathField.setBounds(630,60,140,20);
        // 文本域
        JTextArea adbMonkeyArea = (JTextArea)jComponents.get(12);
        adbMonkeyArea.setBounds(0,0,760,410);
        adbMonkeyArea.setBackground(new Color(47,79,79));
        adbMonkeyArea.setForeground(Color.WHITE);
        adbMonkeyArea.setLineWrap(true);
        adbMonkeyArea.setWrapStyleWord(true);
        adbMonkeyArea.setFont(new Font("微软雅黑",Font.PLAIN,12));
        adbMonkeyArea.setMargin(new Insets(5,5,5,5));
        // 执行按钮
        JButton startButton = (JButton) jComponents.get(13);
        startButton.setBounds(10,100,100,30);
        startButton.setBackground(new Color(248,248,255,255));
        startButton.setBorder(null);
        startButton.setFont(new Font("微软雅黑",Font.PLAIN,14));
        adbMonkey.startMonkeyClick(startButton,"append");
        // 查看日志
        JButton logButton = (JButton) jComponents.get(14);
        logButton.setBounds(170,100,100,30);
        logButton.setBackground(new Color(248,248,255,255));
        logButton.setBorder(null);
        logButton.setFont(new Font("微软雅黑",Font.PLAIN,14));
        // scroll
        JScrollPane jScrollPaneMonkey = (JScrollPane) jComponents.get(15);
        jScrollPaneMonkey.setViewportView(adbMonkeyArea);
        jScrollPaneMonkey.setBounds(10,150,760,410);
        jScrollPaneMonkey.setBorder(null);
        jScrollPaneMonkey.getVerticalScrollBar().setUI(null);
    }
}
